﻿using UnityEngine;

namespace Sliver.Roadnet.Components
{
    public class VehicleEntity : MonoBehaviour
    {
        public int ID;
        
        public void MakeMove(Vector3 target)
        {
            // transform.LookAt(target - transform.position);
            Vector3 delta = target - transform.position;
            if (delta.sqrMagnitude > 0.2f)
            {
                transform.forward = delta;
                transform.position = target;
                transform.Rotate(Vector3.up, -90, Space.Self);
            }
            else
            {
                transform.position = target;
            }
        }

        public static VehicleEntity CreateInstance(Transform parent)
        {
            GameObject o = VehicleManager.RandomVehicleModel();
            o.transform.SetParent(parent);
            VehicleEntity ve = o.AddComponent<VehicleEntity>();
            return ve;
        }
    }
}
